﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_DeleteMail]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_DeleteMail];
GO
CREATE PROCEDURE [dbo].[sproc_DeleteMail] 
    @MailIDS as nvarchar(2000),
    @DeleteType int =0
/*
===============================================================
功能:    删除邮件
参数:
    @MailIDS as nvarchar(2000)    :    被删除的邮件ID集合
    @DeleteType int =0        :    删除类型
备注:    0>>删除标记，1>>物理删除
===============================================================

*/
AS
DECLARE @SQL nvarchar(4000)
IF @DeleteType=0 
BEGIN
    --把邮件仍到垃圾回收里
    SET @SQL = 'UPDATE uds_mailattach SET position =3 WHERE docid in (' + @MailIDS + ')'
    EXEC (@SQL)
END
ELSE
BEGIN
    --删除邮件附件
    SET @SQL = 'DELETE FROM uds_files WHERE docid in (' + @MailIDS + ')'
    EXEC (@SQL)
    --删除邮件相关信息
    SET @SQL = 'DELETE FROM uds_mailattach WHERE docid in (' + @MailIDS + ')'
    EXEC (@SQL)
    --删除邮件主体
    SET @SQL = 'DELETE FROM uds_document WHERE docid in (' + @MailIDS + ')'
    EXEC (@SQL)    
END